var utils = require('./exports/utils')
var constant = require('./exports/constant')
var point_map = require('./exports/point_map')
var ad_util = require('./exports/ad_util')
var ocrUtils = require('./exports/ocrUtils')
//搜一搜赚钱 2次
var search2 = {
  is_first_back: true,
  go_page_from_home() {},
  start() {
    console.log("search2: start");
    this.init();
  },
  init() {
    // 2704
    console.show();
    sleep(1 * 1000);
    var result = ocrUtils.find_text("搜一搜赚钱");
    if (result) {
      var x = result.bounds.centerX();
      var y = result.bounds.centerY();
      console.log("找到【搜一搜赚钱】", "坐标：x: " + x + " y: " + y);
      for (var i = 0; i < 2; i++) {
        utils.click_x_y(x, y);
        sleep(constant.min_click_after_time * 1000);
        utils.click_point.apply(
          utils,
          utils.get_size_point_red_mi([871, 141, 1025, 212])
        );
        sleep(constant.min_click_after_time * 1000);
        var search_swipe_times = 6 + random(0, 2);
        console.log("即将开始滑动--" + search_swipe_times + "--次");
        sleep(1 * 1000);
        while (search_swipe_times > 0) {
          swipe(
            device.width / 2,
            (device.height / 10) * 5,
            device.width / 2,
            (device.height / 10) * 2,
            500
          );
          var watch_search_result_time = 3 + random(0, 2);
          sleep(watch_search_result_time * 1000);
          search_swipe_times = search_swipe_times - 1;
        }
        back();
        if (this.is_first_back) {
          sleep(5 * 1000);
        } else {
          sleep(2 * 1000);
        }
        if (this.is_first_back && utils.click_text_starts_with("残忍离开")) {
          this.is_first_back = false;
          console.log("找到--残忍离开--");
        } else {
          console.log("没找到--残忍离开--");
        }
        sleep(2 * 1000);
      }
    } else {
      console.log("没找到【搜一搜赚钱】");
    }

    console.hide();
    sleep(1 * 1000);
  },
  next() {
    console.log("ad: next");
  },
};

module.exports = search2